package com.syq.handler;

import com.syq.exception.HospitalException;
import com.syq.utils.R;
import enums.HospitalExceptionEnums;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName: HospitalExceptionHandler
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/7/20 21:04
 */

@RestControllerAdvice
public class HospitalExceptionHandler {

    @ExceptionHandler({IncorrectCredentialsException.class, UnknownAccountException.class})
    public R credentialException(){
        return R.error(HospitalExceptionEnums.USERNAME_PASSWORD_ERROR,"");
    }

    @ExceptionHandler(HospitalException.class)
    public R hospitalException(HospitalException ex){
        return R.error(ex.getCode(),ex.getMessage());
    }
}
